function sendLogin(username, password, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:login xmlns:ns0="http://webservice/">' +
            '<username>' + username + '</username>' +
            '<password>' + password + '</password>' +
            '</ns0:login>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}

function sendLogout(callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:logout xmlns:ns0="http://webservice/"/>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}



function sendRegisterUser(user, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:registerUser xmlns:ns0="http://webservice/">' +
            '<userNameField>' + user["userNameField"] + '</userNameField>' +
            '<passwordField>' + user["passwordField"] + '</passwordField>' +
            '<nameField>' + user["nameField"] + '</nameField>' +
            '<identityNumberField>' + user["identityNumberField"] + '</identityNumberField>' +
            '<emailField>' + user["emailField"] + '</emailField>' +
            '<id_country>' + user["id_country"] + '</id_country>' +
            '<id_address>' + user["id_address"] + '</id_address>' +
            '<welcomeMessageField>' + user["welcomeMessageField"] + '</welcomeMessageField>' +
            '<numberSeatsField>' + user["numberSeatsField"] + '</numberSeatsField>' +
            '<plateNumberField>' + user["plateNumberField"] + '</plateNumberField>' +
            '<brandField>' + user["brandField"] + '</brandField>' +
            '<yearField>' + user["yearField"] + '</yearField>' +
            '</ns0:registerUser>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}



function sendEditUser(user, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:editUser xmlns:ns0="http://webservice/">' +
            '<passwordField>' + user["passwordField"] + '</passwordField>' +
            '<nameField>' + user["nameField"] + '</nameField>' +
            '<identityNumberField>' + user["identityNumberField"] + '</identityNumberField>' +
            '<emailField>' + user["emailField"] + '</emailField>' +
            '<id_country>' + user["id_country"] + '</id_country>' +
            '<id_address>' + user["id_address"] + '</id_address>' +
            '</ns0:editUser>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}



function sendEditAdmin(admin, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:editAdmin xmlns:ns0="http://webservice/">' +
            '<passwordField>' + admin["passwordField"] + '</passwordField>' +
            '<nameField>' + admin["nameField"] + '</nameField>' +
            '<identityNumberField>' + admin["identityNumberField"] + '</identityNumberField>' +
            '<emailField>' + admin["emailField"] + '</emailField>' +
            '</ns0:editAdmin>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}


function sendEvaluateTrip(id_trip, car_eval, driver_eval, passenger_eval, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:evaluate xmlns:ns0="http://webservice/">' +
            '<id_trip>' + id_trip + '</id_trip>' +
            '<car_eval>' + car_eval + '</car_eval>' +
            '<driver_eval>' + driver_eval + '</driver_eval>' +
            '<passenger_eval>' + passenger_eval + '</passenger_eval>' +
            '</ns0:evaluate>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}


function sendActivateWaitingAccount(user_id, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:activateWaitingAccount xmlns:ns0="http://webservice/">' +
            '<user_id>' + user_id + '</user_id>' +
            '</ns0:activateWaitingAccount>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}

function sendActivateCancelledAccount(user_id, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:activateCancelledAccount xmlns:ns0="http://webservice/">' +
            '<user_id>' + user_id + '</user_id>' +
            '</ns0:activateCancelledAccount>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}

function sendCancelAccount(reason, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:cancelAccount xmlns:ns0="http://webservice/">' +
            '<reason>' + reason + '</reason>' +
            '</ns0:cancelAccount>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}

function sendRequestCancelledAccountReactivation(callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:requestCancelledAccountReactivation xmlns:ns0="http://webservice/"/>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}

function sendCreateCar(seats, plate, brand, year, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:createCar xmlns:ns0="http://webservice/">' +
            '<numberSeatsField>' + seats + '</numberSeatsField>' +
            '<plateNumberField>' + plate + '</plateNumberField>' +
            '<brandField>' + brand + '</brandField>' +
            '<yearField>' + year + '</yearField>' +
            '</ns0:createCar>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}

function sendEditCar(id_car, seats, plate, brand, year, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:editCar xmlns:ns0="http://webservice/">' +
            '<car_id>' + id_car + '</car_id>' +
            '<numberSeatsField>' + seats + '</numberSeatsField>' +
            '<plateNumberField>' + plate + '</plateNumberField>' +
            '<brandField>' + brand + '</brandField>' +
            '<yearField>' + year + '</yearField>' +
            '</ns0:editCar>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}

function sendRemoveCar(id_car, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:removeCar xmlns:ns0="http://webservice/">' +
            '<car_id>' + id_car + '</car_id>' +
            '</ns0:removeCar>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}


function sendCreateTrip(trip, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:createTrip xmlns:ns0="http://webservice/">' +
            '<departueDate>' + trip["departueDateField"] + '</departueDate>' +
            '<arrivalDate>' + trip["arrivalDateField"] + '</arrivalDate>' +
            '<description>' + trip["descriptionField"] + '</description>' +
            '<id_car>' + trip["carDropDown"] + '</id_car>' +
            '<id_starting_country>' + trip["startingCountryDropDown"] + '</id_starting_country>' +
            '<id_starting_address>' + trip["startingAddressDropDown"] + '</id_starting_address>' +
            '<id_ending_country>' + trip["destinyCountryDropDown"] + '</id_ending_country>' +
            '<id_ending_address>' + trip["destinyAddressDropDown"] + '</id_ending_address>' +
            '</ns0:createTrip>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}


function sendJoinTrip(id_trip, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:joinTrip xmlns:ns0="http://webservice/">' +
            '<id_trip>' + id_trip + '</id_trip>' +
            '</ns0:joinTrip>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}


function sendAcceptUserInTrip(id_trip, user_id, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:acceptUserInTrip xmlns:ns0="http://webservice/">' +
            '<id_trip>' + id_trip + '</id_trip>' +
            '<user_id>' + user_id + '</user_id>' +
            '</ns0:acceptUserInTrip>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}


function sendCreateAddress(countryName, address, lat, lng, callback) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('POST', '/Trabalho_PD/AccountWebService', true);
    var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
            '<soap:Body>' +
            '<ns0:createAddress xmlns:ns0="http://webservice/">' +
            '<countryName>' + countryName + '</countryName>' +
            '<address>' + address + '</address>' +
            '<lat>' + lat + '</lat>' +
            '<lng>' + lng + '</lng>' +
            '</ns0:createAddress>' +
            '</soap:Body>' +
            '</soap:Envelope>';
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState === 4) {
            if (xmlhttp.status === 200) {
                callback($.parseJSON(xmlhttp.responseXML.childNodes.item(0).textContent));
            }
        }
    };
    
    xmlhttp.onerror = function (e) {
        alert("Error contacting server!");
    };

    xmlhttp.setRequestHeader('Content-Type', 'text/xml');
    xmlhttp.send(request);
}